<?php
include "header.php";
?>
<script>change_picture("calculator");</script>
<script>
var n = 0;
var list = new Array();
function remove_constraint(n){
	var rule = "";
	var year = $("#constraint_list_year_"+n).text();
	var term = $("#constraint_list_term_"+n).text();
	var min = $("#constraint_list_min_credit_"+n).text();
	var max = $("#constraint_list_max_credit_"+n).text();
	if (min == "(Unspecified)") min = -1;
	if (max == "(Unspecified)") max = -1;
	rule = rule + year + "_" + term + "_" + min + "_" + max;
	var index = list.indexOf(rule);
	if (index > -1) {
		list.splice(index, 1);
	}
	
	$("#constraint_"+n).remove();
	css_table();
}
function add_constraint(){
	n += 1;
	var rule = "";
	var year = $("#constraint_year").val();
	var term = $("#constraint_term").val();
	var min = $("#constraint_min_credit").val();
	var max = $("#constraint_max_credit").val();
	rule = rule + year + "_" + term + "_" + min + "_" + max;
	list.push(rule);
	if (min == -1) min = "(Unspecified)";
	if (max == -1) max = "(Unspecified)";
	$("#constraint_list").before("<tr id = 'constraint_"+n+"'><td id = 'constraint_list_year_"+n+"'>"+year+"</td><td id = 'constraint_list_term_"+n+"'>"+term+"</td><td id = 'constraint_list_min_credit_"+n+"'>"+(min!=""?min:"Undefined")+"</td><td id = 'constraint_list_max_credit_"+n+"'>"+(max!=""?max:"Undefined")+"</td><td><input type='button' value = 'Remove' onclick = 'remove_constraint("+n+")'/></td></tr>");
	css_table();
}
function submit_form(action_url){
	$('#input_list').val(list);
	$("#specifycredits_form").attr("action", action_url);
	$('#specifycredits_form').submit();
}
</script>
<div>
<h1>Course Schedule Calculator</h1>
<div class = "step_nav">
<a href = "#" onclick = "submit_form('calculator_1.php');"><div id = "step_1" class = "step_button step_on" ></div></a>
<a href = "#" onclick = "submit_form('calculator_2.php');"><div id = "step_2" class = "step_button step_on" ></div></a>
<a href = "#" onclick = "submit_form('calculator_3.php');"><div id = "step_3" class = "step_button step_off" ></div></a>
<a href = "#" onclick = "submit_form('calculator_4.php');"><div id = "step_4" class = "step_button step_off" ></div></a>
</div>
<div class = "step_text">Specify Numbers of Credits for Each Term.</div>
<div class = "form_field">
<form method = "POST" id = "specifycredits_form">
<input type = "hidden" id = "input_list" name = "specifycredits" />
<div>
<table>
<thead>
<tr><td>Year</td><td>Semester</td><td>Min Credits</td><td>Max Credits</td><td>Operation</td></tr>
</thead>
<tbody>
<tr id = "constraint_list" class = "input_tr">
<td>
<div>
<select id = "constraint_year">
<?php
for ($i = $_POST["entry_year"]; $i <= $_POST["graduate_year"]; $i++){
	echo "<option value = '" . $i . "' ";
	//if ($year_1 == i){
	//	echo "Selected";
	//}
	echo " >" . $i . "</option>";
}
?>
</select>
</div>
</td>
<td>
<div>
<select id = "constraint_term">
<option value = 'Spring' >Spring</option>
<option value = 'Fall' >Fall</option>
<option value = 'Summer 1' >Summer 1</option>
<option value = 'Summer 2' >Summer 2</option>
</select>
</div>
</td>
<td>
<div>
<select id = "constraint_min_credit">
<option value = '-1' >(Unspecified)</option>
<?php
for ($i = 6; $i <= 30; $i++){
	echo "<option value = '" . $i . "' >" . $i . "</option>";
}
?>
</select>
</div>
</td>
<td>
<div>
<select id = "constraint_max_credit">
<option value = '-1' >(Unspecified)</option>
<?php
for ($i = 6; $i <= 30; $i++){
	echo "<option value = '" . $i . "' >" . $i . "</option>";
}
?>
</select>
</div>
</td>
<td>
<input type = "button" value = "Add" onclick = "add_constraint();false;" />
</td>
</tr>
</tbody>
</table>
</div>
<div>
</div>
<div class = "next_back">
<a href = "#" onclick = "submit_form('calculator_3.php');"><div class = "next button"></div></a>
<a href = "#" onclick = "submit_form('calculator_1.php');"><div class = "back button"></div></a>
</div>
</form>
</div>
</div>
<?php
include "footer.php";